import java.util.Arrays;
import java.util.Scanner;

public class Test02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        Arrays.sort(arr);
        int min = arr[0] , max = arr[n - 1];
        int ret = max- min;
        for (int i = 1; i < n - 1; i++) {
            int tmp = Math.min(max - arr[i],arr[i] - min);
            ret = Math.min(ret,tmp);
        }
        System.out.println(ret);
    }
}
